<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>我的品酒俱乐部</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<include file="public/comm" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav fs_xl">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title fs_xl">我的品酒俱乐部</h1>
			<a href="javascript:;" class="mui-action-back mui-icon mui-pull-right fs_s" style="line-height: 2em;">俱乐部须知</a>
		</header>
		<include file="public/station_nav" />
		<if $station_info.status == 2>
			<div class="bg_bg">
				<div class=bg_list>
					<a class="fs_l"">{$station_info.refusal}</a>
					<a class="fs_l" id="clear_station">确定</a>
				</div>
			</div>
		</elseif>
		<elseif $station_info.is_lock == 1>
			<div class="bg_bg">
				<div class=bg_list>
					<a class="fs_l"">您的站点已被锁定</a>
				</div>
			</div>
		</elseif>
		</if>
		<div class="mui-content fs_xl" style="padding-bottom: 3em;">
			<div class="club cls">
				<div class="club_img fs_xl">
					<img id="ddd" src="{$station_info.original_img|default='__STATIC__/images/station_logo.png'}" />
					<if $is_captain == 1>
						<p class="fs_m" id="club_img" onclick="$('#doc').click();">修改logo</p>
					</if>
					<input hidden="hidden" type="file" name="file" id="doc" style="width:150px;" onchange="previewImg(this)" />
				</div>
				<div class="club_info fs_xl">
					<p class="fs_m">俱乐部名称：{$station_info.name}</p>
					<p class="fs_m">秘书长：{$station_info.user_name}</p>
					<p class="fs_m">秘书长微信号：{$station_info.user_weixin}</p>
					<p class="fs_m">俱乐部成员：{$station_info.member_count}</p>
				</div>
			</div>
			<div class="club_sy fs_m cls">
				<a class="fs_m" href="{:U('/mobile/station/station_income_detail')}">
					<p class="fs_s">{$station_info.station_income_month_now}</p>
					<p class="fs_s">★本月业绩★</p>
				</a>
				<a class="fs_m">
					<p class="fs_s">{$station_info.station_income}</p>
					<p class="fs_s">累计业绩</p>
				</a>
				<a class="fs_m" href="{:U('/mobile/station/station_funds_detail')}">
					<p class="fs_s">{$station_info.station_money|default=0.00}</p>
					<p class="fs_s">俱乐部经费</p>
				</a>
				<span class="span1 fs_m"></span>
				<span class="span2 fs_m"></span>
			</div>
			<div class="club_m">
				<p class="fs_xl">俱乐部详情说明：</p>
				<p class="fs_m">{$station_info.des} <if $is_captain == 1><a class="re_e fs_s">【重新编辑】</a></if></p>
			</div>
			<div class="edit fs_xl">
				<textarea type="text" class="fs_s" placeholder="详细介绍编辑" name="" id="des_new"></textarea>
				<p class="fs_m"><a class="fs_s" station_id="{$station_info.id}">保存</a></p>
			</div>
			<if $is_station_member == 1>
				<if $is_captain == 1>
				<div class="club_btn">
					<a class="fs_l" href="{:U('/mobile/station/create_station_party')}"><span>申请举办品酒会</span></a>
					<a class="fs_l" href="{:U('/mobile/station/station_funds_apply_detail')}"><span>线下活动经费申请</span></a>
					<a class="fs_l" href="{:U('/mobile/station/party_apply_list')}"><span>品酒会成员申请表</span></a>
					<a class="fs_l" href="{:U('/mobile/station/station_party_list')}"><span>往期品酒会记录</span></a>
					<if $station_info['status'] == 0>
						<a class="fs_l" href="{:U('/mobile/station/create_station_list')}"><span>俱乐部申请进度</span></a>
					</if>
				</div>
				<else />
				<div class="club_btn">
						<a class="fs_l" href="{:U('/mobile/station/join_station_party')}"><span>申请参与品酒会</span></a>
						<a class="fs_l" href="{:U('/mobile/station/my_party_list')}"><span>往期参与记录</span></a>
						<a class="fs_l" href="{:U('/mobile/station/outStation')}"><span>退出品酒俱乐部</span></a>
					</div>
				</if>
			<else />
				<div class="club_btn">
					<a class="fs_l" id="join_station" station_id="{$station_info.id}"><span>申请加入该俱乐部</span></a>
				</div>
			</if>
		</div>
		<script type="text/javascript">
			
			function previewImg(input) {
				if(input.files && input.files[0]) {
					var reader = new FileReader(),
						img = new Image();
					reader.onload = function(e) {
						var imgsrc=document.getElementById('ddd').src;
						if(input.files[0].size > 307200) { //图片大于300kb则压缩
							img.src = e.target.result;
							imgsrc = compress(img);
							img.onload = function() {
// 								document.getElementById('ddd').src = compress(img);
								$.ajax({
									type:"POST",
									url:"/Mobile/Station/upd_station_pic",
									data:{"imgsrc":imgsrc},
									dataType:"json",
									async:false,//同步操作
									success:function(date){
										if(date.status == 1){
											document.getElementById('ddd').src = imgsrc;
										}else{
											alert(date.msg);
											return false;
										}
									}
								});
							}
							
						} else {
// 							document.getElementById('ddd').src = e.target.result;
							imgsrc = e.target.result;
							$.ajax({
								type:"POST",
								url:"/Mobile/Station/upd_station_pic",
								data:{"imgsrc":imgsrc},
								dataType:"json",
								async:false,//同步操作
								success:function(date){
									if(date.status == 1){
										document.getElementById('ddd').src = imgsrc;
									}else{
										alert(date.msg);
										return false;
									}
								}
							});
						}
					}
					reader.readAsDataURL(input.files[0]);
					return 1;
				}
			}
			function compress(img) {
				var initSize = img.src.length;
				var width = img.width;
				var height = img.height;
				var canvas = document.createElement("canvas");
				var ctx = canvas.getContext('2d');
				//如果图片大于四百万像素，计算压缩比并将大小压至400万以下
				var ratio;
				if((ratio = width * height / 4000000) > 1) {
					ratio = Math.sqrt(ratio);
					width /= ratio;
					height /= ratio;
				} else {
					ratio = 1;
				}
				canvas.width = width;
				canvas.height = height;
				//铺底色
				ctx.fillStyle = "#fff";
				ctx.fillRect(0, 0, canvas.width, canvas.height);
				ctx.drawImage(img, 0, 0, width, height);
				//进行最小压缩
				var ndata = canvas.toDataURL("image/jpeg",0.4);
				console.log(ndata.length)
				canvas.width = canvas.height = 0;
				return ndata;
			}
			
			$(function(){
				$(".re_e").click(function(){
					$(".edit").show()
				})
				$(".edit a").click(function(){
					var des_new = $("#des_new").val();
					var station_id = $(this).attr("station_id");
					$.ajax({
						type:"POST",
						url:"/Mobile/station/edit_des",
						data:{"id":station_id,"des":des_new},
						dataType:"json",
						success:function(data){
							alert(data.msg);
							if(data.status == 1){
								location.reload();
							}
						}
					});
					
				})
				$("#clear_station").click(function(){
					$.ajax({
						type:"POST",
						url:"/Mobile/station/clear_station",
						data:{},
						dataType:"json",
						success:function(data){
							if(data.status == 1){
								location.href = "/mobile/station";
							}
						}
					});
				});
				
				$("#join_station").click(function(){
					var station_id = $(this).attr("station_id");
					$.ajax({
						type:"POST",
						url:"/Mobile/station/apply_join_station",
						data:{"station_id":station_id},
						dataType:"json",
						success:function(data){
							alert(data.msg);
						}
					});
				})
			});
			
			
			//兼容调用手机相机
			$(function() {
				var u = navigator.userAgent,
					app = navigator.appVersion;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
				var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if(isAndroid) {
					$("#doc").attr("accept","image/*");
					$("#doc").attr("capture","camera");
				}
				if(isIOS) {
					return false;
				}
			});
		</script>
	</body>

</html>